# encoding: utf-8

import webbrowser,urllib

def main(env):
	queryString = env["context"]["selection"].strip()
	if env["meta"]["richSuffix"]:
		queryString = u"!%s %s" % (env["meta"]["richSuffix"],queryString)
	if env["prefs"]["cwBang_preview"]:
		return [
			("htmlBox",{
				"url": ("%sq=%s" % (env["static"]["cwBang_baseUrl"],queryString)).encode("utf8"),
				"width": 640,
				"height": 480,
				"label": env["static"]["cwBang_label"]
			}),
			("moveCursor",0)
		]
	else:
		url = env["static"]["cwBang_baseUrl"] + urllib.urlencode({"q": queryString.encode("utf8")})
		webbrowser.open(url)
		return [("moveCursor",0)]



